package com.yuewen.permissioncheck.asm;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

/**
 * ASM 类观察者
 * 核心操作
 */
class PermissionClassVisitor extends ClassVisitor {
    private String mClassName;
    private String[] mInterfaces;
    private String superName;

    PermissionClassVisitor() {
        super(Opcodes.ASM6);
    }

    PermissionClassVisitor(ClassVisitor cv) {
        super(Opcodes.ASM6, cv);
    }

    @Override
    public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
        mClassName = name;
        mInterfaces = interfaces;
        this.superName = superName;
        super.visit(version, access, name, signature, superName, interfaces);
    }

    /**
     * 核心修改方法
     * @param access
     * @param name
     * @param desc
     * @param signature
     * @param exceptions
     * @return
     */
    @Override
    public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
        MethodVisitor methodVisitor = cv.visitMethod(access, name, desc, signature, exceptions);
        return new PermissionMethodVisitor(methodVisitor, access, mClassName, name,desc);
    }

    @Override
    public void visitEnd() {
        super.visitEnd();
    }
}
